package com.lhy.utilsdemo.utils.aboutResult;

import lombok.Data;

/**
 * @Auther: LiuHangyu
 * @Date: 2021/05/11
 */
@Data
public class ResultMap<T> {

    //错误码
    private Integer statusCode;

    //错误信息，一般为前端提示信息
    private String message;

    //返回值，一般为成功后返回的数据
    private T data;

    //错误详情，一般为失败后的详细原因，如空指针之类的
//    private String resultDetail;

    public ResultMap() {

    }

    public ResultMap(Integer statusCode, String message) {
        this.statusCode = statusCode;
        this.message = message;
    }

    public ResultMap(Integer statusCode, String message, T data) {
        this.statusCode = statusCode;
        this.message = message;
        this.data = data;
    }

    /**
     * 配合静态对象直接设置 data 参数
     */
    public ResultMap setNewData(T data) {
        ResultMap resultMap = new ResultMap();
        resultMap.setStatusCode(this.statusCode);
        resultMap.setMessage(this.message);
        resultMap.setData(data);
        return resultMap;
    }

    /**
     * 配合静态对象直接设置 errorMsg 参数
     */
    public ResultMap setNewErrorMsg(String message) {
        ResultMap resultMap = new ResultMap();
        resultMap.setStatusCode(this.statusCode);
        resultMap.setMessage(message);
        resultMap.setData(this.data);
        return resultMap;
    }

    public ResultMap setNewResult(Integer statusCode, String message, T data) {
        ResultMap resultMap = new ResultMap();
        resultMap.setStatusCode(statusCode);
        resultMap.setMessage(message);
        resultMap.setData(data);
        return resultMap;
    }


    public static final ResultMap SUCCESS = new ResultMap(200, "ok");

    public static final ResultMap INSERT_SUCCESS = new ResultMap(200, "新增成功");

    public static final ResultMap UPDATE_SUCCESS = new ResultMap(200, "更新成功");

    public static final ResultMap DELETE_SUCCESS = new ResultMap(200, "删除成功");

    public static final ResultMap UPLOAD_SUCCESS = new ResultMap(200, "上传成功");

    public static final ResultMap DOWNLOAD_SUCCESS = new ResultMap(200, "下载成功");

    public static final ResultMap LOGIN_SUCCESS = new ResultMap(200, "登陆成功");

    public static final ResultMap LOGOUT_SUCCESS = new ResultMap(200, "登出成功");

    public static final ResultMap LOGIN_ERROR = new ResultMap(201, "登陆错误");

    public static final ResultMap LOGIN_EXPIRE = new ResultMap(202, "登陆过期");

    public static final ResultMap ACCESS_LIMITED = new ResultMap(301, "访问受限");

    public static final ResultMap ARGS_ERROR = new ResultMap(501, "参数错误");

    public static final ResultMap UNKOWN_ERROR = new ResultMap(502, "系统异常");

    public static final ResultMap INSERT_ERROR = new ResultMap(503, "新增错误");

    public static final ResultMap UPDATE_ERROR = new ResultMap(504, "更新错误");

    public static final ResultMap DELETE_ERROR = new ResultMap(506, "删除错误");

    public static final ResultMap UPLOAD_ERROR = new ResultMap(507, "上传错误");

    public static final ResultMap DOWNLOAD_ERROR = new ResultMap(508, "下载错误");

    public static final ResultMap OTHER_SYSTEM_ERROR = new ResultMap(509, "调用系统异常");
}
